﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PurchaseManagementSystem.DBModel;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;


namespace PurchaseManagementSystem

{
    public class warehouse
    {
        private int orderid { get; set; }
        private int product_employee_id { get; set; }
        private int productid { get; set; }
        public warehouse(int oid,int p_e_i,int pid)               //构造函数，参数oid为传入的订单号，p_e_i为执行的生产部员工号
        {
            orderid = oid;
            product_employee_id = p_e_i;
            productid = pid;
        }
        static string sql = string.Empty;
        public  void GetAllOrder()
        {
           
           // IList<db_init_order> orders = new List<db_init_order>();
           DataTable dt =DBServer.GetOrderByOid_Pid(orderid,productid);
          
            foreach (DataRow row in dt.Rows)
            {
               
                db_init_order order = new db_init_order();
               
                order.Order_num = (int)row["Order_num"];     //物品ID
                order.Employee_id = (int)row["Employee_id"];
                order.Product_id = (int)row["Product_id"];
               order.Order_time = (DateTime)row["Order_time"];
                order.Order_amount = (int)row["Order_amount"];//物品数量
                int balance = DBServer.GetBalanceByProductid(order.Product_id);
                if(balance>=0)
                {
                    int need = balance - order.Order_amount;
              
                    if (need <= 20)                             //物品数量小于等于20时，存入通过订单表。
                    {

                   
                    DBServer.Insertinto_pass(order.Order_num, order.Employee_id, order.Order_time, order.Product_id,order.Order_amount+20);
                  
                    }
                else if(need>20)
                    {
                     DBServer.Insertinto_nopass(order.Order_num,order.Employee_id,order.Order_time,order.Product_id,order.Order_amount,"ENOUGH");
                    }
                 else 
                    {
                     MessageBox.Show("库存小于〇错误，请检查");
                     }
                   
                  }
                else{

                   DBServer.Insertinto_nopass(order.Order_num,order.Employee_id,order.Order_time,order.Product_id,order.Order_amount,"CANNOT_FIND");
                }
            }
        }



    }
}
